<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>本地界面</title>
	</head>
<body>
<h1>通过这个页面来生成博客页面</h1>

<?php	
	$BLOG_URL_ = "http://elfmedy.sinaapp.com";				//博客的地址(后面不带斜杠),全局变量.
	//$LOCAL_POSITION_ = "elfmedy\\";
	$LOCAL_POSITION_ = "svnblog\\1\\";							//博客目录所属的本地目录(自带反斜杠,空字符串就不必了),全局变量.
													//eg "svnblog\\1\\"这个，那么以后通过这个地址找到本地的index为 $LOCAL_POSITION_ . "elfmedy\\"
	$INDEX_NUM_ = 4;								//首页文章的数目,全局变量
	$RSS_NUM_ = 50;									//RSS中的文章数目上限,全局变量
	
/*------------------------------admin--------------------------------------
    index.php
    assist/
        archives.xml
---------------------------------blog--------------------------------------
    blog/
        index.html					//主页
        archives.html
        about.html
        archives/					//归档
            xxxx.php
            xxxx/
        templete/					//模板
            favicon.ico				//-网站图标
            origin/					//-子模板
                index.php
                archives.php
                post.php
                image/
--------------------------------------------------------------------------*/

//function : CoreFunctionAdd 添加新文章
//detial   : CoreFunction的一部分，专门处理添加新文章
function CoreFunctionAdd($stringFileName)
{
	global $LOCAL_POSITION_;
	
	$articalContent = file_get_contents($LOCAL_POSITION_ . "archives\\" . $stringFileName);
	$pathNameArr = explode('.', $stringFileName);
	$pathName = $pathNameArr[0];											// 文章的ID,同时也是文件名(不带后缀)

	preg_match("/<\?php([\s\S]*?)\?>/", $articalContent, $matched);			// 提取并执行文章中的第一段php代码
	eval($matched[1]);														// $title, $date, $category = array(), $tags = array(), $abstract
	$articalListXml = simplexml_load_file("assist\\archives.xml"); 	
	//更新archives中的各项(和summary无关的)
	$findArticleId = $articalListXml->xpath("archive/article[@id=" .$pathName . "]");
	if ($findArticleId != null) return 3;
	$addArticleRoot = $articalListXml->archive->addChild('article');
	$addArticleRoot->addAttribute('id', $pathName);
	$addArticleRoot->addChild('title', $title);
	$addArticleRoot->addChild('link', $stringFileName);
	$addArticleRoot->addChild('time', $date);
	//更新archives中的date 更新summary
	$timeArr = explode('.', $date);
	$findYear = $articalListXml->xpath("summary/time/sepyear[@year=" . $timeArr[0] . "]");
	if ($findYear == null)
	{
		$findYear = $articalListXml->summary->time->addChild('sepyear');
		$findYear->addAttribute('year', $timeArr[0]);
		$findYear->addAttribute('count', '1');
	} else {
		$findYear = $findYear[0];
		$findYear['count'] = strval((int)($findYear['count']) + 1);
	}
	$findMonth = $findYear->xpath("sepmonth[@month=" . $timeArr[1] . "]");
	if ( $findMonth == null)
	{
		$findMonth = $findYear->addChild('sepmonth');
		$findMonth->addAttribute('month', $timeArr[1]);
		$findMonth->addAttribute('count', '1');
	} else {
		$findMonth = $findMonth[0];
		$findMonth['count'] = strval((int)($findMonth['count']) + 1);
	}
	$addSingleDayRoot = $findMonth->addChild('single', $pathName);
	$addSingleDayRoot->addAttribute('day', $timeArr[2]);
	//category 同时更新summary中的category
	$addCategoryRoot = $addArticleRoot->addChild('category');
	foreach ($category as $cat) {
		$addCategoryRoot->addChild('cat', strval($cat));
		$findCategory = $articalListXml->xpath("summary/category/sepcat[@category=\"" . $cat . "\"]"); 	//中文查找的时候还需要带引号
		if ($findCategory == null) return 4;															//对于类别一定要事先存在才能添加进来，而date就不会
		$thisCat = $findCategory[0];
		$thisCat['count'] = strval((int)($thisCat['count']) + 1);
		$addSingleRoot = $thisCat->addChild('single', $pathName);
	}
	
	$addTagsRoot = $addArticleRoot->addChild('tags');
	foreach ($tags as $tag) {
		$addTagsRoot->addChild('tag', strval($tag));
	}
	$addArticleRoot->addChild('abstract', $abstract);
	
	$dom = new DOMDocument('1.0', 'UTF-8');     
	$dom->preserveWhiteSpace = false; 
	$dom->formatOutput = true;	
    $dom->loadXML($articalListXml->asXML());
    $dom->save("assist\\archives.xml");

	return 0;
}


//function : CoreFunctionDelete 删除指定的文章的所有信息
//para     : $stringFileName 需要操作的文件名
//			 $delFile 删除数据库中的内容之后是否需要删除文件（不删除文件用于修改模式，再使用此文件来新建）
//detial   : 包括也会删除实际的文件和相应的文件夹
//			 操作的步骤是先会删除文件夹中的文件，然后才会删除xml数据库中的数据
function CoreFunctionDelete($stringFileName, $delFile)
{
	global $LOCAL_POSITION_;
	
	$articalContent = file_get_contents($LOCAL_POSITION_ . "archives\\" . $stringFileName);
	$pathNameArr = explode('.', $stringFileName);
	$pathName = $pathNameArr[0];											// 文章的ID,同时也是文件名(不带后缀)
	$articalListXml = simplexml_load_file("assist\\archives.xml");
	$articalListDom = new DOMDocument('1.0', 'UTF-8');
	$articalListDom->preserveWhiteSpace = false; 
	$articalListDom->formatOutput = true;	
    $articalListDom->loadXML($articalListXml->asXML());
	$articleListXpath = new DOMXPath($articalListDom);
	//移除archives分支中的文章部分
	$findId = $articleListXpath->query("archive/article[@id=" . $pathName . "]");
	$articleToRemoves = array();
	foreach ($findId as $findArticle) $articleToRemoves[] = $findArticle;
	foreach( $articleToRemoves as $articleDomElement) $articleDomElement->parentNode->removeChild($articleDomElement);
	//对summary中的date统计信息作出修改
	$findDate = $articleListXpath->query("summary/time/sepyear/sepmonth/single[.=" . $pathName . "]");
	$dateToRemoves = array();
	foreach ($findDate as $findDateSingle) $dateToRemoves[] = $findDateSingle;		//循环的时候不能删除，先存起来
	foreach ($dateToRemoves as $dateDomElement)
	{
		$removeLevel = 0;	//为0删除这个节点，为1删除月节点，为2删除年节点
		$monthCount = (int)($dateDomElement->parentNode->getAttribute('count')) - 1;
		if ($monthCount == 0) $removeLevel = 1;	
		$dateDomElement->parentNode->setAttribute('count', strval($monthCount));
		$yearCount = (int)($dateDomElement->parentNode->parentNode->getAttribute('count')) - 1;
		if ($yearCount == 0) $removeLevel = 2;	
		$dateDomElement->parentNode->parentNode->setAttribute('count', strval($yearCount));
		if ($removeLevel == 0) $dateDomElement->parentNode->removeChild($dateDomElement);
		else if ($removeLevel == 1) $dateDomElement->parentNode->parentNode->removeChild($dateDomElement->parentNode);
		else $dateDomElement->parentNode->parentNode->parentNode->removeChild($dateDomElement->parentNode->parentNode);
	}
	//对summary中的category统计信息作出修改
	$findCategory = $articleListXpath->query("summary/category/sepcat/single[.=" . $pathName . "]");
	$categoryToRemoves = array();
	foreach ($findCategory as $findCategorySingle) $categoryToRemoves[] = $findCategorySingle;
	foreach ($categoryToRemoves as $catDomElement)
	{
		$categoryCount = (int)($catDomElement->parentNode->getAttribute('count')) - 1;
		$catDomElement->parentNode->setAttribute('count', strval($categoryCount));
		$catDomElement->parentNode->removeChild($catDomElement);
	}
	$articalListDom->save("assist\\archives.xml");
	$re = 0;
	if ($delFile == 1)
	{
		if (unlink($LOCAL_POSITION_ . "archives\\" . $stringFileName) == FALSE) $re = 2;
		if (file_exists($LOCAL_POSITION_ . "archives\\" . $pathName . "\\"))
			if (rmdir($LOCAL_POSITION_ . "archives\\" . $pathName . "\\") == FALSE)
				$re = 5;
	}
	return $re;
}


//function : CoreFunctionUpdate 对已经存在的文章做出修改
//detial   : CoreFunction的一部分，更新已经存在的文章的信息
//			 实际的做法是先删除在新添加
function CoreFunctionUpdate($stringFileName)
{
	$re = 0;
	$re = CoreFunctionDelete($stringFileName, 0);
	if ($re != 0) return $re;
	$re = CoreFunctionAdd($stringFileName);
	return $re;
}


//function : CreateIndex 构建首页
//para     : $indexArticalNum 首页的文章的数目
//			 $blogIndexUrl 博客首页的地址（用来替换模板中的变量）
//detial   : 读入模板->读取xml文件->替换相应的字符串
function CreateIndex($indexArticalNum, $blogIndexUrl)
{
	global $LOCAL_POSITION_;
	
	$templeteContent = file_get_contents($LOCAL_POSITION_ . "templete\\origin\\index.php");						//读入首页模板到字符串
	$templeteContent = str_replace("{php:content name=\"blogUrl\"}", $blogIndexUrl, $templeteContent );	//-blogUrl
	
	$articalListXml = simplexml_load_file("assist\\archives.xml"); 										//读入文章的xml文件
	
	$startPos = strpos($templeteContent, "[php:repeater name=\"artical\"]");			
	$endPos   = strrpos($templeteContent, "[php:repeater name=\"artical\"]");
	$tagLen   = strlen("[php:repeater name=\"artical\"]");
	$repStr   = substr($templeteContent, $startPos + $tagLen, $endPos - $startPos - $tagLen);			//首页中需要循环替换的地方
	$content  = ""; 
	
	$sumCount = count($articalListXml->archive->children());
	$startCount = $sumCount - 1;
	$endCount   = 0;
	if ($sumCount <= $indexArticalNum) $endCount = 0;
	else $endCount = $sumCount - $indexArticalNum;
	for ( ; $startCount >= $endCount; $startCount--)
	{
		$artical = $articalListXml->archive->article[$startCount];
		$tempStr = $repStr;
		$tempStr = str_replace("{php:content name=\"titleHref\"}", $artical->title, $tempStr);					//-titleHref
		$tempStr = str_replace("{php:content name=\"title\"}", $artical->title, $tempStr);						//-title
		$tempStr = str_replace("{php:content name=\"link\"}", "archives/" . $artical->link, $tempStr);			//-link
		$timeArr = explode('.', $artical->time);
		$timeStr = $timeArr[0] . ' 年 '. $timeArr[1] . ' 月 ' . $timeArr[2] . ' 日';
		$tempStr = str_replace("{php:content name=\"timeHref\"}", $timeStr, $tempStr);							//-timeHref
		$tempStr = str_replace("{php:content name=\"time\"}", $timeStr, $tempStr);								//-time
		$catStr  = "";																							//-categorys
		for ($i = 0; $i < count($artical->category->children()) - 1; $i++)
		{
			$catStr = $catStr . $artical->category->cat[$i] . ', ';
		}
		$catStr = $catStr . $artical->category->cat[$i];
		$tempStr = str_replace("{php:content name=\"category\"}", $catStr, $tempStr);				
		$tempStr = str_replace("{php:content name=\"abstract\"}", trim($artical->abstract), $tempStr);	//-abstract
		$content = $content . $tempStr;
	}
	$templeteContent = substr_replace($templeteContent, $content, $startPos, $endPos - $startPos + $tagLen);
	//打开博客主页，将替换后的内容写到主目录里面的主页
	$blogIndexContent = fopen($LOCAL_POSITION_ . "index.html", "w"); 
	fwrite($blogIndexContent, $templeteContent);
}


/*
<h2>按时间归档：博客至今2年6个月,共有100篇文章</h2>
<ul class="xoxo monthly-archives">
	<li class="archive_yearSum"><span class=\"symbolPlus\">◎</span><a href="#">2010年文章</a> (50)</li>
	<li>
		<ul class="archive_yearSingle">
			<li class="archive_monthSum"><span class="symbolPlus">＋</span><a href="#" title="January 2012">January 2012</a>(11)</li>
			<li class="a_hide">
				<ul class="archive_monthSingle">
					<li><a href="#">具体的某一篇文章</a></li>
					<li><a href="#">具体的某一篇文章</a></li>
					<li><a href="#">具体的某2篇文章</a></li>
				</ul>
			</li>
			<li class="archive_monthSum"><span class="symbolPlus">＋</span><a href="#" title="January 2012">June 2012</a>(15)</li>
			<li class="a_hide">
				<ul class="archive_monthSingle">
					<li><a href="#">具体的某一篇文章</a></li>
					<li><a href="#">具体的某一篇文章</a></li>
					<li><a href="#">具体的某2篇文章</a></li>
				</ul>
			</li>
		</ul>
	</li>
	
	<li class="archive_yearSum"><span class=\"symbolPlus\">◎</span><a href="#">2011年文章</a> (40)</li>
	<li>
		<ul class="archive_yearSingle">
			<li class="archive_monthSum"><span class="symbolPlus">＋</span><a href="#" title="January 2012">January 2012</a>(11)</li>
			<li class="a_hide">
				<ul class="archive_monthSingle">
					<li><a href="#">具体的某一篇文章</a></li>
					<li><a href="#">具体的某一篇文章</a></li>
					<li><a href="#">具体的某2篇文章</a></li>
				</ul>
			</li>
			<li class="archive_monthSum"><span class="symbolPlus">＋</span><a href="#" title="January 2012">June 2012</a>(15)</li>
			<li class="a_hide">
				<ul class="archive_monthSingle">
					<li><a href="#">具体的某一篇文章</a></li>
					<li><a href="#">具体的某一篇文章</a></li>
					<li><a href="#">具体的某2篇文章</a></li>
				</ul>
			</li>
		</ul>
	</li>
</ul>
*/
/*
<h2>按类别排序：共有4个类别，可以针对您感兴趣的类别订阅</h2>
<ul class="xoxo category-archives">
	<li class="cat-item"><span class="symbolPlus">◎</span><a href="#" class="expond">学习</a> (5)</li>
	<li>
		<ul class="archive_catSingle">
			<li><a href="#">具体的某一篇文章</a></li>
			<li><a href="#">具体的某一篇文章</a></li>
			<li><a href="#">具体的某2篇文章</a></li>
		</li>
	</li>
	<li class="cat-item"><span class="symbolPlus">◎</span><a href="#" class="expond">生活</a> (10)</li>
	<li>
		<ul class="archive_catSingle">
			<li><a href="#">具体的某一篇文章</a></li>
			<li><a href="#">具体的某一篇文章</a></li>
			<li><a href="#">具体的某2篇文章</a></li>
		</li>
	</li>
</ul>
*/
//function : CreateArchives 构建归档页面
//para       $blogIndexUrl 博客首页的地址（用来替换模板中的变量）
//detial   : 读入模板->读取xml文件->替换相应的字符串
function CreateArchives($blogIndexUrl)
{
	global $LOCAL_POSITION_;

	$archiveTempleteContent = file_get_contents($LOCAL_POSITION_ . "templete\\origin\\archives.php");			//读入archives.php模板
	$archiveTempleteContent = str_replace("{php:content name=\"blogUrl\"}", $blogIndexUrl, $archiveTempleteContent);	//-blogUrl
	$articalListXml = simplexml_load_file("assist\\archives.xml"); 														//读入文章的xml文件
	
	//按时间归档
	{
		$sumArtical = 0;
		$content = "<ul class=\"xoxo monthly-archives\">";
		for ($i = count($articalListXml->summary->time->children()); $i > 0; $i--)			//年
		{
			$yearArchive = $articalListXml->summary->time->sepyear[$i-1];
			$sumArtical = $sumArtical + $yearArchive['count'];
			$content = $content . "<li class=\"archive_yearSum\"><span class=\"symbolPlus\">◎</span><a href=\"#\">" . $yearArchive['year'] . "年文章</a> (" . $yearArchive['count'] . ")</li>";
			$content = $content . "<li><ul class=\"archive_yearSingle\">";
			for ($j = count($yearArchive->children()); $j > 0; $j--)						//月
			{
				$monthArchive = $yearArchive->sepmonth[$j-1];
				$yearMonthStr = $yearArchive['year'] . " 年 " . $monthArchive['month'] . ' 月';
				$content = $content . "<li class=\"archive_monthSum\"><span class=\"symbolPlus\">＋</span><a href=\"#\" title=\"" . $yearMonthStr . "\">" . $yearMonthStr . "</a> (" . $monthArchive['count'] . ")</li>";
				$content = $content . "<li class=\"a_hide\"><ul class=\"archive_monthSingle\">";
				for ($k = count($monthArchive->children()); $k > 0; $k--)					//日
				{
					$dayArchive = $monthArchive->single[$k-1];
					$searchArticel = $articalListXml->xpath("archive/article[@id=" .$dayArchive . "]");
					$thisArticle = $searchArticel[0];
					$content = $content . "<li><a href=\"" . "archives/" . $thisArticle->link . "\">" . $thisArticle->title . "</a></li>";
				}
				$content = $content . "</ul></li>";
			}
			$content = $content . "</ul></li>";
		}
		$content = $content . "</ul>";
		$contentHeader = "<h2>按时间归档：共有" . $sumArtical . "篇文章</h2>";
		$archiveTempleteContent = str_replace("{php:content name=\"achiveByTime\"}", $contentHeader . $content, $archiveTempleteContent);
	}
	
	//按类别归档
	{
		$content = "<ul class=\"xoxo category-archives\">";
		foreach ($articalListXml->summary->category->sepcat as $sepCategory)
		{
			$content = $content . "<li class=\"cat-item\"><span class=\"symbolPlus\">◎</span><a href=\"#\" class=\"expond\">" . $sepCategory['category'] . "</a> (" . $sepCategory['count'] . ")</li>";
			$content = $content . "<li><ul class=\"archive_catSingle\">";
			for ($i = count($sepCategory->children()); $i > 0; $i--)
			{
				$singleArticle = $sepCategory->single[$i-1];
				$searchAtricle = $articalListXml->xpath("archive/article[@id=" . $singleArticle . "]");
				$thisArticle = $searchAtricle[0];
				$content = $content . "<li><a href=\"" . "archives/" . $thisArticle->link . "\">" . $thisArticle->title . "</a></li>";
			}
			$content = $content . "</ul></li>";
		}
		$content = $content . "</ul>";
		$contentHeader = "<h2>按类别排序：共有" . count($articalListXml->summary->category->children()) . "个类别，可以针对您感兴趣的类别订阅</h2>";
		$archiveTempleteContent = str_replace("{php:content name=\"achiveByCategory\"}", $contentHeader . $content, $archiveTempleteContent);
	}
	
	//按专题归档
	{
		$contentHeader = "<h2>按专题归档：作者自己对部分文章做了归类</h2>";
		$archiveTempleteContent = str_replace("{php:content name=\"achiveBySpe\"}", $contentHeader, $archiveTempleteContent);
	}
	
	$blogArchiveContent = fopen($LOCAL_POSITION_ . "archives.html", "w"); 
	fwrite($blogArchiveContent, $archiveTempleteContent);   
}


//function : CreatePost 构建文章模板页面
//para       $blogIndexUrl 博客首页的地址（用来替换模板中的变量）
//detial   : 其实就是替换文章模板页面中的首页地址而已
//			 只会替换模板一次，以后就不会替换了
function CreatePost($blogIndexUrl)
{
	global $LOCAL_POSITION_;
	
	if (file_exists($LOCAL_POSITION_ . "templete\\origin\\posttop_done.php") == FALSE)
	{
		$postTopTempleteContent = file_get_contents($LOCAL_POSITION_ . "templete\\origin\\posttop.php");					//读入posttop.php模板
		$postTopTempleteContent = str_replace("{php:content name=\"blogUrl\"}", $blogIndexUrl, $postTopTempleteContent);	//-blogUrl
		$topContent = fopen($LOCAL_POSITION_ . "templete\\origin\\posttop_done.php", "w"); 
		fwrite($topContent, $postTopTempleteContent);
	}
	
	if (file_exists($LOCAL_POSITION_ . "templete\\origin\\postbottom_done.php") == FALSE)
	{
		$postBotTempleteContent = file_get_contents($LOCAL_POSITION_ . "templete\\origin\\postbottom.php");					//读入postbottom.php模板
		$postBotTempleteContent = str_replace("{php:content name=\"blogUrl\"}", $blogIndexUrl, $postBotTempleteContent);	//-blogUrl
		$botContent = fopen($LOCAL_POSITION_ . "templete\\origin\\postbottom_done.php", "w"); 
		fwrite($botContent, $postBotTempleteContent);
	}
}


//function : CreateRss 生成RSS文件
//para       $blogIndexUrl 博客首页的地址（用来替换模板中的变量）
//detial   : 静态生成RSS文件
function CreateRss($rssNum, $blogIndexUrl)
{
	global $LOCAL_POSITION_;
	
	$templeteContent = file_get_contents("assist\\rssTemplete.xml");			//读入RSS模板
	$templeteContent = str_replace("{php:content name=\"blogUrl\"}", $blogIndexUrl, $templeteContent );	//-blogUrl
	
	$articalListXml = simplexml_load_file("assist\\archives.xml"); 										//读入文章的xml文件
	
	$startPos = strpos($templeteContent, "[php:repeater name=\"artical\"]");			
	$endPos   = strrpos($templeteContent, "[php:repeater name=\"artical\"]");
	$tagLen   = strlen("[php:repeater name=\"artical\"]");
	$repStr   = substr($templeteContent, $startPos + $tagLen, $endPos - $startPos - $tagLen);			//首页中需要循环替换的地方
	$content  = ""; 
	
	$sumCount = count($articalListXml->archive->children());
	$startCount = $sumCount - 1;
	$endCount   = 0;
	if ($sumCount <= $rssNum) $endCount = 0;
	else $endCount = $sumCount - $rssNum;
	date_default_timezone_set('PRC');
	for ( ; $startCount >= $endCount; $startCount--)
	{
		$artical = $articalListXml->archive->article[$startCount];
		$tempStr = $repStr;
		$tempStr = str_replace("{php:content name=\"title\"}", $artical->title, $tempStr);						//-title
		$tempStr = str_replace("{php:content name=\"link\"}", $blogIndexUrl . "/archives/" . $artical->link, $tempStr);			//-link
		$timeArr = explode('.', $artical->time);
		$timeStr = date(DATE_RSS, mktime(0, 0, 0, (int)($timeArr[1]), (int)($timeArr[2]), (int)($timeArr[0])));
		$tempStr = str_replace("{php:content name=\"time\"}", $timeStr, $tempStr);								//-time			
		$tempStr = str_replace("{php:content name=\"abstract\"}", trim($artical->abstract), $tempStr);			//-abstract
		$content = $content . $tempStr;
	}
	$templeteContent = substr_replace($templeteContent, $content, $startPos, $endPos - $startPos + $tagLen);
	//打开博客主页，将替换后的内容写到主目录里面的主页
	$blogRssContent = fopen($LOCAL_POSITION_ . "rss.xml", "w"); 
	fwrite($blogRssContent, $templeteContent);
}


//function: CoreFunction
//para: $stringFileName 待处理的文件
//		$intFunctionNum 处理的命令。1是加入新的文章，2是用当前文件去修改数据库中的文章，3是删除文章
//return : 	1 没有找到指定的文件（指定要操作的文件不存在，请检查网站archives目录下是否有相应的文件）
//			2 删除文件失败，请手动删除（网站的archives目录下）
//			3 添加新文章的时候文件的ID和已经存在的文章的ID相同（在数据库中已经有一篇文章和当前文
//			  章的文件名即ID相同，可以选择update模式来更新掉原来的文章）
//			4 添加新文章的时候没有找到类别（请先建立相应的类别才能添加文章到这个类别中）
//			5 删除和文件相对应的目录失败，请手动删除（网站的archives目录下）
//			
//			255 操作的命令不正确，应该是1,2,3
function CoreFunction($stringFileName, $intFunctionNum)
{
	global $LOCAL_POSITION_, $BLOG_URL_, $INDEX_NUM_, $RSS_NUM_;
	
	@$articalContent = file_get_contents($LOCAL_POSITION_ . "archives\\" . $stringFileName);
	if ($articalContent == FALSE) return 1;
	$re = 0;
	
	if ($intFunctionNum == 1) $re = CoreFunctionAdd($stringFileName);
	else if ($intFunctionNum == 2) $re = CoreFunctionUpdate($stringFileName);
	else if ($intFunctionNum == 3) $re = CoreFunctionDelete($stringFileName, 1);
	else $re = 255;
	
	$blogIndexUrl = $BLOG_URL_;

	CreateIndex($INDEX_NUM_, $BLOG_URL_);			//建立主页
	CreateArchives($BLOG_URL_);						//建立归档页面
	CreatePost($BLOG_URL_);							//替换文章模板页面
	CreateRss($RSS_NUM_, $BLOG_URL_);				//生成RSS
	
	return $re;
}


//function : HandleCategory 增加或者删除类别
//para     : $strCategory 需要增加或者删除的类别
//			 $actionCode 命令。为1表示增加类别，为2表示删除类别
//return   : 1  已经存在这个类别，不需要添加
//           2  要求删除的类别不存在
//			 255 actionCode不正确（只能去1和2）
//detial   : 如果某些文章本来存在某一类别中，但是使用此函数删除了这个类别，那么文章依旧存在，类别不在了
//			 可以通过修改文章并提交来改变文章的类别，使之归入某类
function HandleCategory($strCategory, $actionCode)
{
	$articalListXml = simplexml_load_file("assist\\archives.xml");
	$findCategory = $articalListXml->xpath("summary/category/sepcat");
	//添加
	if ($actionCode == 1)
	{
		while(list( , $node) = each($findCategory))
		{
			if ($strCategory == $node['category']) return 1;
		}
		$addCategory = $articalListXml->summary->category->addChild('sepcat');
		$addCategory->addAttribute('category', $strCategory);
		$addCategory->addAttribute('count', '0');
		$articalListXml->asXML("assist\\archives.xml");
	}
	//删除
	else if ($actionCode == 2)
	{
		$findDelFlag = 0;
		while(list( , $node) = each($findCategory))
		{
			if ($strCategory == $node['category'])
			{
				$findDelFlag = 1;
				break;
			}
		}
		if ($findDelFlag == 1)
		{
			//del
			$articalListDom = new DOMDocument('1.0', 'UTF-8');
			$articalListDom->preserveWhiteSpace = false; 
			$articalListDom->formatOutput = true;	
			$articalListDom->loadXML($articalListXml->asXML());
			
			$findCategory = $articalListDom->getElementsByTagName('sepcat');
			foreach($findCategory as $singleCat)   
			{   
				if($singleCat->getAttribute('category') == $strCategory)    
				{   
					$singleCat->parentNode->removeChild($singleCat);
					break;	//删除第一个（循环删除会有毛病）
				}
			}
			$articalListDom->save("assist\\archives.xml");
		}
		else
		{
			return 2;
		}
	}
	else return 255;
	return 0;
}

//function : GetCategory 返回类别的数组
//return   : 数组
function GetCategory()
{
	$articalListXml = simplexml_load_file("assist\\archives.xml");
	$findCategory = $articalListXml->xpath("summary/category/sepcat");
	$reArr = array();
	while(list( , $node) = each($findCategory))
	{
		$reArr[] = $node['category'];
	}
	return $reArr;
}


$re = CoreFunction("0001.php", 2);
//$re = CoreFunction("0006.php", 3);
//$re = CoreFunction("0008.php", 3);
//$re = CoreFunction("0009.php", 3);
echo '返回值是' . $re . '<br />';

//$ha = HandleCategory("基础学习", 1);
//$ha = HandleCategory("小小应用", 1);
//$ha = HandleCategory("哈哈", 2);
//echo '返回值是' . $ha . '<br />';
// $arr = GetCategory();
// foreach($arr as $ff)
// {
	// echo "类别：" , $ff , "<br />";
// }
?>

</body>
</html>